﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using G.Navigate;

namespace FY13.View
{
    public partial class ChangePasswordPage : GBasePage
    {
        public ChangePasswordPage()
        {
            InitializeComponent();
        }
        Data.UserInfo user;
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            string email = this.NavigationContext.QueryString["userid"];
            user = GloabalData.Instance.FYDataBase.Users.First(c => c.Email == email);
        }
        private void btnOk_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(txtPWD.Password))
            {
                MessageBox.Show("请输入密码！", "提示", MessageBoxButton.OK);
                return;
            }
            if (string.IsNullOrEmpty(txtPWD_Confirm.Password))
            {
                MessageBox.Show("请输入确认密码！", "提示", MessageBoxButton.OK);
                return;
            }
            if (txtPWD.Password != txtPWD_Confirm.Password)
            {
                MessageBox.Show("两次密码输入不一样，请重新输入！", "提示", MessageBoxButton.OK);
                return;
            }
            user.Password = txtPWD.Password;
            GloabalData.Instance.FYDataBase.SubmitChanges();//保存更改的密码
            if (chkRemenberMe.IsChecked == true)
                GloabalData.Instance.AutoLoginId = user.Email;
            else
                GloabalData.Instance.AutoLoginId = null;
            GloabalData.Instance.CurrentUser = user;
            this.NavigationService.Navigate(string.Format("/View/Index.xaml?userid={0}", user.Email));
        }

        private void btnCancel_Click(object sender, RoutedEventArgs e)
        {
            if (this.NavigationService.CanGoBack)
                this.NavigationService.GoBack();
        }
    }
}